#include <iostream>
#include <string>
#include <sstream>
#include <string.h>

#define LINE "\r\n"
#define LINESIZE strlen(LINE)

namespace httptool
{
    
    class Request
    {
    public:
        Request()
        {
        }

        // get url _httpversion\r\n
        bool getandsubstrline()
        {
            auto pos = _reqBuffer.find(LINE);
            if(pos == std::string::npos) return false;
            std::string line = _reqBuffer.substr(0,pos);
            _reqBuffer.erase(0,pos);

            std::stringstream ss(line);
            ss >> _means >> _url >> _httpversion;
            //使用 sstream流进行输入
            return true;
        }

    public:
        std::string _means;
        std::string _url;
        std::string _httpversion;

        std::string _statusline;
        std::string _readHeader;
        std::string _readgas;
        std::string _readsize;

        std::string _reqBuffer;
    };

    class Responce
    {
    public:
        Responce()
        {
        }

    public:
        std::string _respBuffer;
    };

    void responceMessage(const Request& req ,Responce& resp)
    {
         std::string send = "";
         std::string start = "-------------------------------------------hello  world------------------------------------------\r\n";
         std::string end = "-------------------------------------------beybye world------------------------------------------\r\n";
       
         start += req._means;
         start += LINE;
         start += req._url;
         start += LINE;
         start += req._httpversion;
         start += LINE;
         start += req._reqBuffer;
         start += end;

         std:: cout << start << std::endl;
        
        std::string respBlank = "http/1.1 200 ok\r\n";
        std::string respheader = "Content-Type: text/html\r\n";
        std::string respgas = LINE;
        std::string boby = "<html lang=\"en\"><head><meta charset=\"UTF-8\"><title>新余早报</title><h1>我市开展《一路畅通》活动</h1></head><body><p>新余交通广播《一路畅通》“交通大家谈”节目，特邀新余市交通委员会地面公交运营管理处处长姜晓丽、新余市公安局公安交通管理局秩序处副处长姜大丽、新余交通发展研究院交通规划所所长姜小丽为您解答公交车专用道6月1日起社会车辆进出公交车道须注意哪些?</p></body></html>";

        //send += start;
        send += respBlank;
        send += respheader;
        send += respgas;
        send += boby;
        //send += end;

        resp._respBuffer = send;
    }
}
